package net.xiangcaowuyu.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import net.xiangcaowuyu.springcloud.entites.CommonResult;
import net.xiangcaowuyu.springcloud.entites.Payment;
import net.xiangcaowuyu.springcloud.service.PaymentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 博客：https://www.xiangcaowuyu.net
 * Description:
 *
 * @Author: 香草物语
 * DateTime: 2021-07-24 11:45
 */
@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @PostMapping("/create")
    public CommonResult<Payment> create(@RequestBody Payment payment) {
        int result = paymentService.create(payment);
        log.info("*****插入结果：" + result);
        log.info("O(∩_∩)O");
        if (result > 0) {
            return new CommonResult<>(200, "插入数据库成功");
        } else {
            return new CommonResult<>(444, "插入数据库失败");
        }

    }

    @GetMapping("/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        log.info("******获取到结果:" + payment);
        log.info("O(∩_∩)O111");
        if (payment != null) {
            return new CommonResult<>(200, "获取数据成功", payment);
        } else {
            return new CommonResult<>(444, "没有对应记录");
        }
    }

}
